const { ccclass, property } = cc._decorator;

@ccclass
export default class pfGoods extends cc.Component {
    @property(cc.SpriteFrame)
    goodsTypeArr: cc.SpriteFrame[] = [];
    @property(cc.Sprite)
    spBulletType: cc.Sprite = null;
    index = 0;

    onLoad() {
        this.index = Math.round(Math.random() * this.goodsTypeArr.length);
        this.spBulletType.spriteFrame = this.goodsTypeArr[this.index];
        this.changeBulletType();
    }

    //1.5秒切换子弹类型
    changeBulletType() {
        let self = this;
        this.scheduleOnce(() => {
            self.index += 1;
            if (self.index > self.goodsTypeArr.length - 1) self.index = 0;
            self.spBulletType.spriteFrame = self.goodsTypeArr[self.index];
            self.changeBulletType();
        }, 1.5)
    }

    update() {
        this.node.y -= 3;
        if (this.node.y <= -800) {
            this.node.destroy();
        }
    }
}
